package org.wattdepot.simulation.oahugrid.main.batch;

import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.wattdepot.simulation.oahugrid.demandcurve.DailyDemandCurve;
import org.wattdepot.simulation.oahugrid.demandcurve.StandardDemandCurve;
import org.wattdepot.simulation.oahugrid.demandcurve.WeekendDemandCurve;
import org.wattdepot.simulation.oahugrid.demandcurve.DailyDemandCurve.PeakType;
import org.wattdepot.simulation.oahugrid.powerplant.PowerPlant;

/**
 * Tests the simulation.
 * 
 * @author Philip Johnson
 */
public class TestBatchSimulation {

  /**
   * Just checks to make sure Simulation doesn't throw an error.
   * 
   * @throws Exception If problems occur.
   */
  @Test
  public void testSimulation() throws Exception {
    // Simulation simulation = new Simulation();
    DailyDemandCurve curve = new StandardDemandCurve(Tstamp.makeTimestamp("2009-11-01"));
    // System.out.println(curve.toString());
    assertEquals("Test peak caching", 500, curve.getPeakMaxMW(PeakType.OFFPEAK));
    assertEquals("Test peak caching", 660, curve.getPeakMaxMW(PeakType.SHOULDERPEAK));
    assertEquals("Test peak caching", 1060, curve.getPeakMaxMW(PeakType.PRIORITYPEAK));
    curve.addRandomVariation(5);
    new WeekendDemandCurve(Tstamp.makeTimestamp("2009-11-01"));
    //System.out.println(curve.toString());
  }

  /**
   * Ensures that one line of output is created for each power plant at each timestamp.
   *  
   * @throws Exception If problems occur.
   */
  //@Ignore
  @Test
  public void testAllPlantsOutput() throws Exception {
    BatchSimulation simulation = new BatchSimulation();
    String outputString = simulation.getData();
    char cr = System.getProperty("line.separator").charAt(0);

    // With samples every 15 minutes, should have 4 samples per hour, 24 hours a day, plus 1 for
    // header line
    int numLinesExpected = simulation.getNumDays() * 4 * 24 * PowerPlant.values().length + 1;
    int numLines = 0;
    for (int i = 0; i < outputString.length(); i++) {
      if (outputString.charAt(i) == cr) {
        numLines++;
      }
    }
    assertEquals("Output does not contain expected number of lines", numLinesExpected, numLines);
  }
}
